//
//  VideoTableViewCell.m
//  LOL视频播放
//
//  Created by 花花蔡 on 2016/12/8.
//  Copyright © 2016年 com.HuaHuaCai. All rights reserved.
//

#import "VideoTableViewCell.h"
#import "Public.h"
#import "UIImageView+WebCache.h"
@interface VideoTableViewCell ()

@property(nonatomic,strong) UIImageView *backImageView;

//头像
@property(nonatomic,strong) UIImageView *videoImageView;
//标题
@property(nonatomic,strong) UILabel *videoTitleLabel;

//时间
@property(nonatomic,strong) UILabel *videoTimeLabel;

//视频数量
@property(nonatomic,strong) UILabel *videoCountLabel;

@end

@implementation VideoTableViewCell


+(instancetype)loadCellWithTableView:(UITableView *)tableView {
   
    static NSString *cellIdentifier = @"cellIdent";
    VideoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if (!cell) {
        cell = [[VideoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}

//赋值
- (void)setModel:(VideoModel *)model {
    NSURL *url = [NSURL URLWithString:model.P];
    [self.videoImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"占位图"]];
    self.videoTitleLabel.text = model.T;
    
    if (![model.V isEqualToString:@"0"]) {
        
        if ([model.V intValue] > 10000)
            self.videoCountLabel.text = [NSString stringWithFormat:@"%d万次播放",[model.V intValue]/10000];
        else
            self.videoCountLabel.text = [NSString stringWithFormat:@"%d次播放",[model.V intValue] ];
    }else
        self.videoCountLabel.text = [NSString stringWithFormat:@"%d次播放",[model.V intValue] ];
    
    //找到字符串中含T的部分并把T替换成双空格
    NSString *date = [model.A stringByReplacingOccurrencesOfString:@"T" withString:@"  "];
    self.videoTimeLabel.text = date;

}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    //图片框
    self.videoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(6*KWidth_ScaleW, 6*KWidth_ScaleW, 128*KWidth_ScaleW, 98*KWidth_ScaleW)];
    //切圆角
    self.videoImageView.layer.cornerRadius = 7;
    self.videoImageView.layer.masksToBounds = YES;
    [self.contentView addSubview:self.videoImageView];
    
    //标题
    _videoTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(146*KWidth_ScaleW, 0, screen_width - 146*KWidth_ScaleW, 67*KWidth_ScaleW)];
    _videoTitleLabel.font = [UIFont systemFontOfSize:21*KWidth_ScaleW];
    _videoTitleLabel.numberOfLines = 0;
    _videoTitleLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_videoTitleLabel];
    
    //时间
    _videoTimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(146*KWidth_ScaleW, 86*KWidth_ScaleW,screen_width - 240*KWidth_ScaleW, 18*KWidth_ScaleW)];
    _videoTimeLabel.font = [UIFont systemFontOfSize:15*KWidth_ScaleW];
    _videoTimeLabel.textColor = [UIColor grayColor];
    [self.contentView addSubview:_videoTimeLabel];
    
    //视频
    _videoCountLabel = [[UILabel alloc] initWithFrame:CGRectMake( screen_width - 112 * KWidth_ScaleW, 86*KWidth_ScaleW, 104*KWidth_ScaleW, 18*KWidth_ScaleW)];
    _videoCountLabel.font = [UIFont systemFontOfSize:15 * KWidth_ScaleW];
    _videoCountLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:_videoCountLabel];
}


- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
